package com.networks;

import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 网络编程学习
 */
public class Example {
    public static void main(String[] args) {
        System.out.println("网络编程开始学习，认清形势，少点幻想！");
    }

    @Test
    public void go() {
        System.out.println("减少幻想驱动");
    }

    @Test
    public void come() {
        // 幻想驱动
        //
    }

    @Test
    public void network() {
        try {
            // 查询本机地址
            // 127.0.0.1
            InetAddress byName = InetAddress.getByName("127.0.0.1");
            System.out.println(byName);
            InetAddress localhost = InetAddress.getByName("localhost"); // localhost/127.0.0.1
            System.out.println(localhost);
            InetAddress host = InetAddress.getLocalHost(); // 内网 DESKTOP-VOT0UEI/10.0.0.196
            System.out.println(host);
            // 查询百度
            InetAddress baiDu = InetAddress.getByName("www.baidu.com");
            System.out.println(baiDu); // www.baidu.com/14.215.177.38
            // 常用方法（了解）
            System.out.println(baiDu.getCanonicalHostName()); // ip 14.215.177.38
            System.out.println(baiDu.getHostAddress()); // ip 14.215.177.38
            System.out.println(baiDu.getHostName()); // 获取域名 www.baidu.com
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
